# The decimal context
import decimal
decimal.getcontext()


#The Decimal constructor
decimal.Decimal(5)

from decimal import Decimal
Decimal(7)
Decimal('0.8')
Decimal('0.8') - Decimal('0.7')


#Constructing Decimals from fractional values
Decimal(0.8) - Decimal(0.7)

decimal.getcontext().traps[decimal.FloatOperation] = True
Decimal(0.8) - Decimal(0.7)
Decimal('0.8') > 0.7


#Decimal stores precision
a = Decimal(3)
b = Decimal('3.0')
c = Decimal('3.00')
a
b
c

a * 2
b * 2
c * 2

decimal.getcontext().prec = 6
d = Decimal('1.234567')
d
d + Decimal(1)


#Special values
Decimal('Infinity')
Decimal('-Infinity')
Decimal('NaN')
Decimal('NaN') + Decimal('1.414')

#Interaction with other numeric types
Decimal('1.4') + 0.6


#Operations with Decimal

(-7) % 3 

from decimal import Decimal
Decimal(-7) % Decimal(3)

def is_odd(n):
    return n % 2 == 1

is_odd(2)
is_odd(3)
is_odd(-2)
is_odd(-3)

is_odd(2.0)
is_odd(3.0)
is_odd(-2.0)
is_odd(-3.0)

is_odd(Decimal(2))
is_odd(Decimal(3))
is_odd(Decimal(-2))
is_odd(Decimal(-3))
Decimal(-3) % 2

def is_odd(n):
    return n % 2 != 0

is_odd(Decimal(-3))


#Integer division
-7 // 3
Decimal(-7) // Decimal(3)


# The math module
Decimal('0.81').sqrt()